package com.core.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ApplicationContextEvent;

/**
 * spring.factories 配置 SpringContextUtil，将 SpringContextUtil 注入到 容器中
 */
public class SpringContextUtil implements ApplicationListener<ApplicationContextEvent> {

    private static ApplicationContext applicationContext;

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    @Override
    public void onApplicationEvent(ApplicationContextEvent event) {
        SpringContextUtil.applicationContext = event.getApplicationContext();
    }
}
